#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5,mod=1e9+7;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-48,ch=getchar();}
	return x*f;
}
int T,A,B,C,ans;

int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=res*x;
		x=x*x;
		y>>=1;
	}
	return res;
}

signed main(){
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	T=read();
	while(T--){
		A=read(),B=read(),C=read(),ans=0;
		for(int i=1;i<=A;i++)
			for(int j=1;j<=B;j++)
				for(int k=1;k<=C;k++)
					ans+=(ksm(j,i)==ksm(i,k));
		printf("%lld\n",ans%mod);
	}
	return 0;
}